<?php


namespace app\api\controller;
use app\common\controller\Api;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Request;
use think\Db;
/**
 * 购物车
 */
class Printr extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [''];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    public function printinfobyid(){

        $id=$this->request->param('id');

        $log=Db::name('newphoto')->where(['id'=>$id])->find();
        $case=Db::name('aa_case')->where(['id'=>$log['caseid']])->find();

        $keys='bd99559952c44ce0a9dd6207f1ab3fbd';
        $user='359183874@qq.com';
        $timestamp=time();


        $sing=SHA1($user.$keys.$timestamp);


        $data['user']=$user;
        $data['timestamp']=$timestamp;
        $data['sign']=$sing;

        $data['sn']='29WNE39EB31B54A';
        $data['content']='<PAGE>
                            <SIZE>40,51</SIZE>
                            <IMG x="60" y="16" w="100">
                            <L x="12" y="80" w="288" h="4">：
                            <TEXT font="9" x="24" y="100" w="1" h="1" r="0">品名：'.$log['title'].'</TEXT>
                            <TEXT font="9" x="24" y="135" w="1" h="1" r="0">颜色：'.$log['color1'].'</TEXT>
                            <TEXT font="9" x="24" y="170" w="1" h="1" r="0">SKU：'.$log['sku'].'</TEXT>
                            <TEXT font="9" x="24" y="205" w="1" h="1" r="0">项目：'. mb_substr($case['title'],0,12).'</TEXT>
                            <TEXT font="9" x="24" y="235" w="1" h="1" r="0">'.mb_substr($case['title'],12).'</TEXT>
                             <QRC  x="108" y="275" s="5" e="L">'.$log['sku'].'</QRC>
                            </PAGE>';

        $url='https://open.xpyun.net/api/openapi/xprinter/printLabel';


        $header = array('Content-Type:application/json;charset=UTF-8');


        $ch = curl_init();    // 启动一个CURL会话
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        curl_setopt($ch, CURLOPT_POST, true); // 发送一个常规的Post请求
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));     // Post提交的数据包
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);     // 设置超时限制防止死循环
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        //curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     // 获取的信息以文件流的形式返回
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头
        $result = curl_exec($ch);

        curl_close($ch);

//        var_dump($result);
        $result=json_decode($result,true);
        $this->success($result['msg']);

    }
}
/**
 *Title:打印信息
 *<br/>By: 18161043652 2022/12/30 12:03
 */


